package com.fa.controller;

import com.fa.common.annotation.Anonymous;
import com.fa.common.core.controller.BaseController;
import com.fa.common.core.domain.AjaxResult;
import com.fa.common.core.page.TableDataInfo;
import com.fa.domain.MdUnitDTO;
import com.fa.domain.MdUnitMeasure;
import com.fa.domain.MdVendor;
import com.fa.service.IMdUnitService;
import com.fa.service.impl.MdUnitServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/maindata/unit")
public class MdUnitController extends BaseController {
@Autowired
private IMdUnitService mdUnitService;
@Anonymous
    @GetMapping("/list")
    public TableDataInfo selectMdUnitList(MdUnitDTO mdUnitDTO) {
    System.out.println(mdUnitDTO);

        List<MdUnitMeasure> list = mdUnitService.selectMdUnitList(mdUnitDTO);
        System.out.println("-------------");
        System.out.println(list);
        return getDataTable(list);
    }


    /**
     * 查询所有主单位
     */
    @GetMapping("/list/primary")
    public AjaxResult selectMdUnitListPrimary() {
        List<MdUnitMeasure> list = mdUnitService.selectMdUnitListPrimary();
        return AjaxResult.success(list);
    }
//添加 单位
    @PostMapping("/add")
    public AjaxResult add(@RequestBody MdUnitMeasure mdUnitMeasure) {
        return toAjax(mdUnitService.add(mdUnitMeasure));
    }

    /**
     * 修改 单位
     */
    @Anonymous
    @PostMapping(value = "/{unitId}")
    public AjaxResult edit(@PathVariable int unitId, @RequestBody MdUnitMeasure mdUnitMeasure )
    {
        System.out.println(unitId);
        System.out.println(mdUnitMeasure);
        return toAjax(mdUnitService.updateMdUnit(mdUnitMeasure));
    }

    /**
     * 删除 单位
     */
    @Anonymous
    @DeleteMapping("/delete/{unitId}")
    public AjaxResult remove(@PathVariable long unitId)
    {
        System.out.println(unitId);
        return toAjax(mdUnitService.delete(unitId));

    }
}
